package com.devframe.component.ftlprocess.freemarker.handle;


import java.io.IOException;
import java.io.Writer;
import java.util.Locale;
import java.util.Map;


import org.apache.log4j.Logger;

import com.devframe.component.ftlprocess.FTLProcessGlobalConstants;
import com.devframe.component.ftlprocess.freemarker.context.MyFTLProcessHandleContext;


import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

/**
 *说明：render标记的解析
 *@创建：作者:詹保山(zbs),softzbs@126.com  创建时间：
 *@修改历史：
 *		[序号](zbs	Sep 18, 2009)<修改说明>
 */
public class RenderHandler {
	private static Logger logger = Logger.getLogger(RenderHandler.class);
	private MyFTLProcessHandleContext handleContext;
	private Configuration configuration;
	
	public RenderHandler(MyFTLProcessHandleContext handleContext ){
		this.handleContext=handleContext;
		this.configuration=handleContext.getRenderConfiguration();
	}
	public  void process(Writer writer ,String templateName, Map<String, Object> root){
		//加入公共的指令
		root.putAll(this.handleContext.getDirectives());
		Template temp;
		  try {
			temp = this.configuration.getTemplate(templateName);
			temp.process(root, writer);
			writer.flush();
			writer.close();
			
		} catch (IOException e) {
			logger.error(e);
			e.printStackTrace();
		} catch (TemplateException e) {
			logger.error(e);
			e.printStackTrace();
		}
		
		
	}
	
	
	
}

